using System;
using System.Collections.Generic;
using Xunit;
using static SmartSite.Frame.FrameTypeEnum;

namespace SmartSite.Frame.Test
{
    public class IdentityAckRestoreFrame : RestoreFrame
    {
        protected override FrameTypeEnum Key { get { return IdentityAckFrameType; } }

        public static IdentityAckFrame CreateForTest()
        {
            IdentityAckFrame frame = new IdentityAckFrame();
            frame.FactoryCode.Value = 4;
            frame.MonitorDeviceId.Value = "000000000000223";
            frame.ValidationCode.Value = ValidationCodeEnum.success;
            frame.CommunicationId.Value = (new List<byte> { 88, 77, 66 }).ToArray().ToULong();
            frame.ServerDateTime.Value = DateTime.Parse("2019-7-11 17:40:55");
            frame.CRC.Value = frame.CalculationCRC();
            return frame;
        }

        public IdentityAckRestoreFrame(RestoreFrameCollection restoreFrameDict)
            : base(restoreFrameDict) { }


        protected override BaseFrame GetReferenceFrame() => new IdentityAckFrame();

        protected override void OnRestored(RestoredData restored)
        {
            base.OnRestored(restored);

            Assert.IsType<IdentityAckFrame>(restored.Frame);
            IdentityAckFrame frame = (IdentityAckFrame)restored.Frame;

            Assert.Equal(frame.Buffer, State.BufferClone());
            Assert.Equal(BaseFrameDataEnum.ProtocolVersion, frame.ProtocolVersion.Value);
            Assert.Equal(BaseFrameDataEnum.FactoryCode, frame.FactoryCode.Value);
            Assert.Equal("000000000000223", frame.MonitorDeviceId.Value);
            Assert.Equal((new byte[] { 88, 77, 66 }).ToULong(), frame.CommunicationId.Value);
            Assert.Equal(DateTime.Parse("2019-7-11 17:40:55"), frame.ServerDateTime.Value);
            Assert.Equal(3492, frame.CRC.Value);
            throw new IdentityAckRestoredFrameException();
        }
    }
}
